const salesService = require('../services/salesService');

const getSales = async (req, res) => {
  try {
    const sales = await salesService.getSales(req.query);
    res.status(200).json(sales);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
};

const addSales = async (req, res) => {
  try {
    const newSales = await salesService.addSales(req.body);
    res.status(201).json(newSales);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
};

const updateSales = async (req, res) => {
  try {
    const updatedSales = await salesService.updateSales(req.params.id, req.body);
    res.status(200).json(updatedSales);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
};

const deleteSales = async (req, res) => {
  try {
    await salesService.deleteSales(req.params.id);
    res.status(200).json({ message: `Sales deleted with ID: ${req.params.id}` });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
};

const getSuggestions = async (req, res) => {
  try {
    const suggestions = await salesService.getSuggestions(req.query);
    res.status(200).json(suggestions);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
};

module.exports = {
  getSales,
  addSales,
  updateSales,
  deleteSales,
  getSuggestions,
};
